
// ***********************************************************************
// AUTO GENERATED CLASS - Do Not Modify this file, if needed modify .tt
// ***********************************************************************
// Assembly         : InnovaApp_DomainLayer
// Author           : LJO+01
// Created          : 17/11/2013 20:29:50
// ***********************************************************************
// <copyright file="N.A." company="Copyright © Innovacall 2011">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// Domain layer  
// DomainClass
// </summary>
// ***********************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;


namespace InnovaApp.Layers.DomainLayer
{
    /// <summary>
    /// Class ManagedContent
    /// </summary>
    [Serializable]
    public partial class ManagedContent : _DomainLayer_Base  
    {
        #region Primitive Properties
    	
        /// <summary>
        /// Gets or sets Id.
        /// </summary>
        /// <value>The Id.</value>
        public virtual int Id
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets FK_Structure_Page.
        /// </summary>
        /// <value>The FK_Structure_Page.</value>
        /// <remarks>
        /// Foregn key of ManagedContent
        /// 
        /// </remarks>
        public virtual int FK_Structure_Page
        {
            get { return _fK_Structure_Page; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_Structure_Page != value)
                    {
                        if (Structure_Page != null && Structure_Page.Id != value)
                        {
                            Structure_Page = null;
                        }
                        _fK_Structure_Page = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private int _fK_Structure_Page;
    	
        /// <summary>
        /// Gets or sets FK_AppUser_Creator.
        /// </summary>
        /// <value>The FK_AppUser_Creator.</value>
        /// <remarks>
        /// Foregn key of ManagedContent
        /// 
        /// </remarks>
        public virtual System.Guid FK_AppUser_Creator
        {
            get { return _fK_AppUser_Creator; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_AppUser_Creator != value)
                    {
                        if (InnoAppUser != null && InnoAppUser.Id != value)
                        {
                            InnoAppUser = null;
                        }
                        _fK_AppUser_Creator = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private System.Guid _fK_AppUser_Creator;
    	
        /// <summary>
        /// Gets or sets FK_AppUser_LastModificator.
        /// </summary>
        /// <value>The FK_AppUser_LastModificator.</value>
        /// <remarks>
        /// Foregn key of ManagedContent
        /// 
        /// </remarks>
        public virtual Nullable<System.Guid> FK_AppUser_LastModificator
        {
            get { return _fK_AppUser_LastModificator; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_AppUser_LastModificator != value)
                    {
                        if (InnoAppUser1 != null && InnoAppUser1.Id != value)
                        {
                            InnoAppUser1 = null;
                        }
                        _fK_AppUser_LastModificator = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private Nullable<System.Guid> _fK_AppUser_LastModificator;
    	
        /// <summary>
        /// Gets or sets Creation.
        /// </summary>
        /// <value>The Creation.</value>
        public virtual System.DateTime Creation
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets LastUpdate.
        /// </summary>
        /// <value>The LastUpdate.</value>
        public virtual Nullable<System.DateTime> LastUpdate
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets ResumeText.
        /// </summary>
        /// <value>The ResumeText.</value>
        public virtual string ResumeText
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets ResumeHTML.
        /// </summary>
        /// <value>The ResumeHTML.</value>
        public virtual string ResumeHTML
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets ContentText.
        /// </summary>
        /// <value>The ContentText.</value>
        public virtual string ContentText
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets ContentHTML.
        /// </summary>
        /// <value>The ContentHTML.</value>
        public virtual string ContentHTML
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets CSSExtension.
        /// </summary>
        /// <value>The CSSExtension.</value>
        public virtual string CSSExtension
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets JSExtension.
        /// </summary>
        /// <value>The JSExtension.</value>
        public virtual string JSExtension
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets rowversion.
        /// </summary>
        /// <value>The rowversion.</value>
        public virtual byte[] rowversion
        {
            get;
            set;
        }

        #endregion

        #region Navigation Properties
    
        /// <summary>
        /// Link ManagedContent to all Article
        /// </summary>
        public virtual ICollection<Article> Article
        {
            get
            {
                if (_article == null)
                {
                    var newCollection = new FixupCollection<Article>();
                    newCollection.CollectionChanged += FixupArticle;
                    _article = newCollection;
                }
                return _article;
            }
            set
            {
                if (!ReferenceEquals(_article, value))
                {
                    var previousValue = _article as FixupCollection<Article>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupArticle;
                    }
                    _article = value;
                    var newValue = value as FixupCollection<Article>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupArticle;
                    }
                }
            }
        }
        private ICollection<Article> _article;
        public virtual ArticleComment ArticleComment
        {
            get { return _articleComment; }
            set
            {
                if (!ReferenceEquals(_articleComment, value))
                {
                    var previousValue = _articleComment;
                    _articleComment = value;
                    FixupArticleComment(previousValue);
                }
            }
        }
        private ArticleComment _articleComment;
        public virtual InnoAppUser InnoAppUser
        {
            get { return _innoAppUser; }
            set
            {
                if (!ReferenceEquals(_innoAppUser, value))
                {
                    var previousValue = _innoAppUser;
                    _innoAppUser = value;
                    FixupInnoAppUser(previousValue);
                }
            }
        }
        private InnoAppUser _innoAppUser;
        public virtual InnoAppUser InnoAppUser1
        {
            get { return _innoAppUser1; }
            set
            {
                if (!ReferenceEquals(_innoAppUser1, value))
                {
                    var previousValue = _innoAppUser1;
                    _innoAppUser1 = value;
                    FixupInnoAppUser1(previousValue);
                }
            }
        }
        private InnoAppUser _innoAppUser1;
        public virtual Structure_Page Structure_Page
        {
            get { return _structure_Page; }
            set
            {
                if (!ReferenceEquals(_structure_Page, value))
                {
                    var previousValue = _structure_Page;
                    _structure_Page = value;
                    FixupStructure_Page(previousValue);
                }
            }
        }
        private Structure_Page _structure_Page;

        #endregion

        #region Association Fixup
    
        private bool _settingFK = false;
    
        private void FixupArticleComment(ArticleComment previousValue)
        {
            if (previousValue != null && ReferenceEquals(previousValue.ManagedContent, this))
            {
                previousValue.ManagedContent = null;
            }
    
            if (ArticleComment != null)
            {
                ArticleComment.ManagedContent = this;
            }
        }
    
        private void FixupInnoAppUser(InnoAppUser previousValue)
        {
            if (previousValue != null && previousValue.ManagedContent.Contains(this))
            {
                previousValue.ManagedContent.Remove(this);
            }
    
            if (InnoAppUser != null)
            {
                if (!InnoAppUser.ManagedContent.Contains(this))
                {
                    InnoAppUser.ManagedContent.Add(this);
                }
                if (FK_AppUser_Creator != InnoAppUser.Id)
                {
                    FK_AppUser_Creator = InnoAppUser.Id;
                }
            }
        }
    
        private void FixupInnoAppUser1(InnoAppUser previousValue)
        {
            if (previousValue != null && previousValue.ManagedContent1.Contains(this))
            {
                previousValue.ManagedContent1.Remove(this);
            }
    
            if (InnoAppUser1 != null)
            {
                if (!InnoAppUser1.ManagedContent1.Contains(this))
                {
                    InnoAppUser1.ManagedContent1.Add(this);
                }
                if (FK_AppUser_LastModificator != InnoAppUser1.Id)
                {
                    FK_AppUser_LastModificator = InnoAppUser1.Id;
                }
            }
            else if (!_settingFK)
            {
                FK_AppUser_LastModificator = null;
            }
        }
    
        private void FixupStructure_Page(Structure_Page previousValue)
        {
            if (previousValue != null && previousValue.ManagedContent.Contains(this))
            {
                previousValue.ManagedContent.Remove(this);
            }
    
            if (Structure_Page != null)
            {
                if (!Structure_Page.ManagedContent.Contains(this))
                {
                    Structure_Page.ManagedContent.Add(this);
                }
                if (FK_Structure_Page != Structure_Page.Id)
                {
                    FK_Structure_Page = Structure_Page.Id;
                }
            }
        }
    
        private void FixupArticle(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Article item in e.NewItems)
                {
                    item.ManagedContent = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Article item in e.OldItems)
                {
                    if (ReferenceEquals(item.ManagedContent, this))
                    {
                        item.ManagedContent = null;
                    }
                }
            }
        }

        #endregion

    }
}
